<template>
  <el-dialog :title="$t('orderList.allList.opera.passTitle')" :visible.sync="showState" :before-close="handleClose" :close-on-click-modal="false">
    <el-form ref="formValidate" :model="formValidate" label-width="150px" class="demo-ruleForm">
      <el-form-item :label="$t('orderList.allList.opera.remarks')">
        <el-input
          v-model="formValidate.creditIdeaRemark"
          type="textarea"
          :autosize="{ minRows: 4, maxRows: 6}"
          :placeholder="$t('orderList.allList.opera.inputRemarks')"
          :maxlength="200"
          show-word-limit
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">{{ $t('common.operate.close') }}</el-button>
      <el-button type="primary" :loading="submitLoading" @click="handleSubmit">{{ $t('common.operate.sure') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { riskAudit } from '@/api/auth'
export default {
  name: 'PassDialog',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      submitLoading: false,
      formValidate: {
        creditIdeaRemark: null
      }
    }
  },
  computed: {
    showState: {
      get: function() {
        return this.showDialog
      },
      set: function() {
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('change-dialog', 'isPass', false)
      setTimeout(() => {
        this.formValidate = {
          creditIdeaRemark: null
        }
      }, 10)
    },
    handleSubmit() {
      this.submitLoading = true
      const data = {
        creditOrderId: this.$route.query.order,
        creditIdeaRemark: this.formValidate.creditIdeaRemark,
        isPass: true,
        closeCreditOrder: false
      }
      riskAudit(data)
        .then(res => {
          this.submitLoading = false
          if (res.success) {
            this.$message.success(this.$t('common.tips.operateSuccess'))
            this.$emit('edit-success')
            this.handleClose()
          } else {
            this.$message.error(res.message)
          }
        })
        .catch(err => {
          this.$message.error(err.message)
          this.submitLoading = false
        })
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-select{
    width: 100%;
  }
  .admin-tree{
    margin-top: 20px;
  }
</style>
